/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NguoiDungInternalFrame.java
 *
 * Created on Jul 29, 2010, 5:46:35 AM
 */

package GUI;

import BUS.NguoiDungBUS;
import POJO.NguoiDungPOJO;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author DarkMagikian
 */
public class NguoiDungInternalFrame extends javax.swing.JInternalFrame {

    /** Trạng thái của hai button Thêm & Cập nhật */
    private boolean TrangThai;
    /*
     * TrangThai = true  => Thêm mới
     * TrangThai = false => Cập nhật
     */
    ArrayList<NguoiDungPOJO> NDList = NguoiDungBUS.selectAll();
    public void showList(){
        try{
            ArrayList<NguoiDungPOJO> List = NguoiDungBUS.selectAll();
            this.NDList = List;
            DefaultTableModel dtm = new DefaultTableModel() {
                @Override
                public boolean isCellEditable(int row, int column) {
                    return false;
                }
            };
            dtm.addColumn("STT");
            dtm.addColumn("Tên người dùng");
            dtm.addColumn("Tài khoản");
            dtm.addColumn("Mật mã");
            int size = List.size();
            dtm.setRowCount(size);
            for(int i=0;i<size;i++){
                dtm.setValueAt(i+1, i, 0);
                dtm.setValueAt(List.get(i).getTenNguoiDung(), i, 1);
                dtm.setValueAt(List.get(i).getTaiKhoan(), i, 2);
                dtm.setValueAt(List.get(i).getMatMa(), i, 3);
            }
            this.jTDanhSach.setModel(dtm);
            this.jTDanhSach.changeSelection(0, 0, false, false);
            this.jLThongTin.setText("Người dùng đang lựa chọn");
            this.setInfo();
        }catch(Exception ex){
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }

    public void setInfo(){
        int row = this.jTDanhSach.getSelectedRow();
        if(row>=0){
            this.jTFTenNguoiDung.setText(NDList.get(row).getTenNguoiDung());
            this.jTFTaiKhoan.setText(NDList.get(row).getTaiKhoan());
            this.jTFMatMa.setText(NDList.get(row).getMatMa());
            this.jCBCMon.setSelected(NDList.get(row).isBCMon());
            this.jCDSHocSinh.setSelected(NDList.get(row).isDSHocSinh());
            this.jCNhapDiem.setSelected(NDList.get(row).isNhapDiem());
            this.jCQLHocSinh.setSelected(NDList.get(row).isQLHocSinh());
            this.jCQLLop.setSelected(NDList.get(row).isQLLop());
            this.jCQLMonHoc.setSelected(NDList.get(row).isQLMonHoc());
            this.jCQLNamHoc.setSelected(NDList.get(row).isQLNamHoc());
            this.jCQLQuyDinh.setSelected(NDList.get(row).isQLQuyDinh());
            this.jCXepLop.setSelected(NDList.get(row).isXepLop());
        }
    }

    public void setButton(boolean onoff){
        this.jBLuu.setEnabled(!onoff);
        this.jBHuy.setEnabled(!onoff);
        this.jBThem.setEnabled(onoff);
        this.jBXoa.setEnabled(onoff);
        this.jBCapNhat.setEnabled(onoff);
    }

    public void setCheckBox(boolean onoff){
        this.jCBCMon.setEnabled(onoff);
        this.jCDSHocSinh.setEnabled(onoff);
        this.jCNhapDiem.setEnabled(onoff);
        this.jCQLHocSinh.setEnabled(onoff);
        this.jCQLLop.setEnabled(onoff);
        this.jCQLMonHoc.setEnabled(onoff);
        this.jCQLNamHoc.setEnabled(onoff);
        this.jCQLQuyDinh.setEnabled(onoff);
        this.jCXepLop.setEnabled(onoff);
    }


    /** Creates new form NguoiDungInternalFrame */
    public NguoiDungInternalFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jPanel1 = new javax.swing.JPanel();
        jLThongTin = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTFTenNguoiDung = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTFTaiKhoan = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTFMatMa = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jCQLNamHoc = new javax.swing.JCheckBox();
        jCQLLop = new javax.swing.JCheckBox();
        jCQLHocSinh = new javax.swing.JCheckBox();
        jCQLMonHoc = new javax.swing.JCheckBox();
        jCQLQuyDinh = new javax.swing.JCheckBox();
        jCDSHocSinh = new javax.swing.JCheckBox();
        jCBCMon = new javax.swing.JCheckBox();
        jCNhapDiem = new javax.swing.JCheckBox();
        jCXepLop = new javax.swing.JCheckBox();
        jBLuu = new javax.swing.JButton();
        jBHuy = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTDanhSach = new javax.swing.JTable();
        jBThem = new javax.swing.JButton();
        jBXoa = new javax.swing.JButton();
        jBCapNhat = new javax.swing.JButton();
        jBThoat = new javax.swing.JButton();
        jBLamMoi = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setTitle("Quản lý học sinh - Quản lý người dùng");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 24));
        jLabel1.setForeground(new java.awt.Color(0, 102, 255));
        jLabel1.setText("Quản lý người dùng");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông tin", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 51, 255))); // NOI18N

        jLThongTin.setText("Người dùng đang chọn");

        jLabel3.setText("Tên người dùng:");

        jTFTenNguoiDung.setEnabled(false);

        jLabel4.setText("Tài khoản:");

        jTFTaiKhoan.setEnabled(false);

        jLabel5.setText("Mật mã:");

        jTFMatMa.setEnabled(false);

        jLabel6.setText("Các chức năng có thể thực hiện");

        jCQLNamHoc.setText("Quản lý năm học");
        jCQLNamHoc.setEnabled(false);

        jCQLLop.setText("Quản lý lớp học");
        jCQLLop.setEnabled(false);

        jCQLHocSinh.setText("Quản lý học sinh");
        jCQLHocSinh.setEnabled(false);

        jCQLMonHoc.setText("Quản lý môn học");
        jCQLMonHoc.setEnabled(false);

        jCQLQuyDinh.setText("Quản lý quy định");
        jCQLQuyDinh.setEnabled(false);

        jCDSHocSinh.setText("Xem danh sách học sinh");
        jCDSHocSinh.setEnabled(false);

        jCBCMon.setText("Báo cáo tổng kết môn");
        jCBCMon.setEnabled(false);

        jCNhapDiem.setText("Nhập bảng điểm");
        jCNhapDiem.setEnabled(false);

        jCXepLop.setText("Lập danh sách lớp");
        jCXepLop.setEnabled(false);

        jBLuu.setText("Lưu");
        jBLuu.setEnabled(false);
        jBLuu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBLuuActionPerformed(evt);
            }
        });

        jBHuy.setText("Hủy");
        jBHuy.setEnabled(false);
        jBHuy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBHuyActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLThongTin)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jCQLNamHoc)
                                    .addComponent(jCQLLop)
                                    .addComponent(jCQLHocSinh))
                                .addGap(26, 26, 26)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jCQLQuyDinh)
                                    .addComponent(jCQLMonHoc)
                                    .addComponent(jCXepLop))
                                .addGap(32, 32, 32)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jCBCMon)
                                    .addComponent(jCNhapDiem)
                                    .addComponent(jCDSHocSinh)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel5))
                                .addGap(33, 33, 33))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTFTaiKhoan)
                            .addComponent(jTFMatMa)
                            .addComponent(jTFTenNguoiDung, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 64, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jBHuy, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jBLuu, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(58, 58, 58))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLThongTin)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jTFTaiKhoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jTFMatMa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jTFTenNguoiDung, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(jBLuu)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBHuy)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jCQLNamHoc)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jCQLLop)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jCQLHocSinh))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jCQLMonHoc)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jCQLQuyDinh)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jCXepLop)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jCDSHocSinh)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jCNhapDiem)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jCBCMon)))
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Danh sách", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 51, 255))); // NOI18N

        jTDanhSach.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jTDanhSach.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTDanhSachMouseClicked(evt);
            }
        });
        jTDanhSach.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTDanhSachKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(jTDanhSach);

        jBThem.setText("Thêm");
        jBThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBThemActionPerformed(evt);
            }
        });

        jBXoa.setText("Xóa");
        jBXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBXoaActionPerformed(evt);
            }
        });

        jBCapNhat.setText("Cập nhật");
        jBCapNhat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCapNhatActionPerformed(evt);
            }
        });

        jBThoat.setText("Thoát");
        jBThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBThoatActionPerformed(evt);
            }
        });

        jBLamMoi.setText("Làm mới");
        jBLamMoi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBLamMoiActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE)
                .addGap(10, 10, 10)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jBThem, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                    .addComponent(jBXoa, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jBCapNhat, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jBLamMoi, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jBThoat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jBThem)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBXoa)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBCapNhat)
                        .addGap(73, 73, 73)
                        .addComponent(jBLamMoi)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBThoat))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(147, 147, 147)
                        .addComponent(jLabel1)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        // TODO add your handling code here:
        this.showList();
    }//GEN-LAST:event_formInternalFrameOpened

    private void jBThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBThemActionPerformed
        // TODO add your handling code here:
        this.setButton(false);
        this.jTFTenNguoiDung.setEnabled(true);
        this.jTFTenNguoiDung.setText(null);
        this.jTFMatMa.setEnabled(true);
        this.jTFMatMa.setText(null);
        this.jTFTaiKhoan.setEnabled(true);
        this.jTFTaiKhoan.setText(null);
        this.jTFTaiKhoan.requestFocus();
        this.setCheckBox(true);

        this.TrangThai = true;
    }//GEN-LAST:event_jBThemActionPerformed

    private void jBCapNhatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCapNhatActionPerformed
        // TODO add your handling code here:
        this.setButton(false);
        this.jTFTenNguoiDung.setEnabled(true);
        this.jTFMatMa.setEnabled(true);
        this.jTFTenNguoiDung.requestFocus();
        this.setCheckBox(true);

        this.TrangThai = false;
    }//GEN-LAST:event_jBCapNhatActionPerformed

    private void jBXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBXoaActionPerformed
        // TODO add your handling code here:
        int xacnhan = JOptionPane.showConfirmDialog(this, "Bạn thực sự muốn xóa người dùng '"+this.jTFTenNguoiDung.getText()+"' ?", "Xác nhận", JOptionPane.YES_NO_OPTION);
        if(xacnhan==0){
            boolean kq = NguoiDungBUS.delete(this.jTFTaiKhoan.getText());
            if (kq == false) {
                JOptionPane.showMessageDialog(this, "Xóa thất bại");
            }
            this.showList();
        }
    }//GEN-LAST:event_jBXoaActionPerformed

    private void jBLamMoiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBLamMoiActionPerformed
        // TODO add your handling code here:
        this.showList();
    }//GEN-LAST:event_jBLamMoiActionPerformed

    private void jBThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBThoatActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jBThoatActionPerformed

    private void jBHuyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBHuyActionPerformed
        // TODO add your handling code here:
        this.setButton(true);
        this.jTFTenNguoiDung.setEnabled(false);
        this.jTFMatMa.setEnabled(false);
        this.jTFTaiKhoan.setEnabled(false);
        this.setCheckBox(false);
    }//GEN-LAST:event_jBHuyActionPerformed

    private void jBLuuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBLuuActionPerformed
        // TODO add your handling code here:
        boolean kq = false;
        String error_message = "";
        boolean error = false;

        String TenND = this.jTFTenNguoiDung.getText();
        String TaiKhoan = this.jTFTaiKhoan.getText();
        String MatMa = this.jTFMatMa.getText();
        ///
        String BCMon = String.valueOf(this.jCBCMon.isSelected());
        String DSHocSinh = String.valueOf(this.jCDSHocSinh.isSelected());
        String NhapDiem = String.valueOf(this.jCNhapDiem.isSelected());
        String QLHocSinh = String.valueOf(this.jCQLHocSinh.isSelected());
        String QLLop = String.valueOf(this.jCQLLop.isSelected());
        String QLMonHoc = String.valueOf(this.jCQLMonHoc.isSelected());
        String QLNamHoc = String.valueOf(this.jCQLNamHoc.isSelected());
        String QLQuyDinh = String.valueOf(this.jCQLQuyDinh.isSelected());
        String XepLop = String.valueOf(this.jCXepLop.isSelected());
        /////
        if (this.TrangThai) {
            int n = this.jTDanhSach.getRowCount();
            for(int i=0;i<n;i++){
                if(this.jTFTaiKhoan.getText().compareToIgnoreCase(this.jTDanhSach.getValueAt(i, 2).toString())==0){
                    error = true;
                    error_message += "Tài khoản đã tồn tại.\n";
                    this.jTFTaiKhoan.requestFocus();
                    this.jTFTaiKhoan.selectAll();
                    break;
                }
            }
            if (TenND.isEmpty()) {
                error_message += "Tên người dùng không được để trống.\n";
                error = true;
            }
            if (TaiKhoan.isEmpty()) {
                error_message += "Tài khoản không được để trống.\n";
                error = true;
            }
            if (MatMa.isEmpty()) {
                error_message += "Mật mã không được để trống.\n";
                error = true;
            }
            if(error){
                JOptionPane.showMessageDialog(this, error_message, "Thông báo", JOptionPane.ERROR_MESSAGE);
            } else {
                kq = NguoiDungBUS.insert(TaiKhoan, TenND, MatMa, QLNamHoc, QLLop, QLHocSinh, QLMonHoc, QLQuyDinh, DSHocSinh, XepLop,NhapDiem,BCMon);
                if (kq) {
                    JOptionPane.showMessageDialog(this, "Thêm thành công.");
                } else {
                    JOptionPane.showMessageDialog(this, "Thêm thất bại");
                }
                this.setButton(true);
                this.jTFMatMa.setEnabled(false);
                this.jTFTenNguoiDung.setEnabled(false);
                this.jTFTaiKhoan.setEnabled(false);
                this.setCheckBox(false);
                this.showList();
            }
        }else{
                kq = NguoiDungBUS.update(TaiKhoan, TenND, MatMa, QLNamHoc, QLLop, QLHocSinh, QLMonHoc, QLQuyDinh, DSHocSinh, XepLop,NhapDiem,BCMon);
                if (kq) {
                    JOptionPane.showMessageDialog(this, "Cập nhật thành công.");
                } else {
                    JOptionPane.showMessageDialog(this, "Cập nhật thất bại");
                }
                this.setButton(true);
                this.jTFMatMa.setEnabled(false);
                this.jTFTenNguoiDung.setEnabled(false);
                this.jTFTaiKhoan.setEnabled(false);
                this.setCheckBox(false);
                this.showList();
            }
        
    }//GEN-LAST:event_jBLuuActionPerformed

    private void jTDanhSachMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTDanhSachMouseClicked
        // TODO add your handling code here:
        this.setInfo();
    }//GEN-LAST:event_jTDanhSachMouseClicked

    private void jTDanhSachKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTDanhSachKeyReleased
        // TODO add your handling code here:
        if(evt.getKeyCode()==38 || evt.getKeyCode()==40)  this.setInfo();
        if(evt.getKeyCode()==127)  this.jBXoaActionPerformed(null);
    }//GEN-LAST:event_jTDanhSachKeyReleased


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jBCapNhat;
    private javax.swing.JButton jBHuy;
    private javax.swing.JButton jBLamMoi;
    private javax.swing.JButton jBLuu;
    private javax.swing.JButton jBThem;
    private javax.swing.JButton jBThoat;
    private javax.swing.JButton jBXoa;
    private javax.swing.JCheckBox jCBCMon;
    private javax.swing.JCheckBox jCDSHocSinh;
    private javax.swing.JCheckBox jCNhapDiem;
    private javax.swing.JCheckBox jCQLHocSinh;
    private javax.swing.JCheckBox jCQLLop;
    private javax.swing.JCheckBox jCQLMonHoc;
    private javax.swing.JCheckBox jCQLNamHoc;
    private javax.swing.JCheckBox jCQLQuyDinh;
    private javax.swing.JCheckBox jCXepLop;
    private javax.swing.JLabel jLThongTin;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTable jTDanhSach;
    private javax.swing.JTextField jTFMatMa;
    private javax.swing.JTextField jTFTaiKhoan;
    private javax.swing.JTextField jTFTenNguoiDung;
    // End of variables declaration//GEN-END:variables

}
